﻿using BasecampRestAPI;
using NUnit.Framework;
using TestBasecampRestAPI.TestMoveToDoList;

namespace TestBasecampRestAPI
{
	[TestFixture]
	public class TestCategory
	{
		FakeBaseCamp _camp;
		FakeRestWebService _service;
		ICategory _category;

		[SetUp]
		public void SetUp()
		{
			_camp = FakeBaseCamp.GetInstance();
			_service = FakeRestWebService.GetInstance();
			_camp.ServiceGetFakeResult = _service;
			_category = Category.GetInstance(_camp, TestBasecamp.GetElementForXml(Properties.Resources.FakeCategory));
		}

		[Test]
		public void Construct()
		{
			Assert.IsNotNull(_category);
			Assert.AreEqual(1366, _category.Id);
			Assert.AreEqual("Poofy Goofs", _category.Name);
			Assert.AreEqual(10, _category.ElementsCount);
			Assert.AreEqual(CategoryType.Post, _category.Type);
		}

		[Test]
		public void GetProject()
		{
			_camp.GetProjectByIdFakeResult =
				Project.GetInstance(_camp, TestBasecamp.GetElementForXml(Properties.Resources.FakeProject));
			IProject project = _category.Project;
			Assert.IsNotNull(project);
			Assert.AreEqual(6969, project.Id);
		}

		[Test]
		public void SetName()
		{
			const string newName = "New Name";
			_category.Name = newName;
			Assert.AreEqual(newName, _category.Name);
			Assert.IsTrue(_camp.ServiceGetCalled);
		}

		[Test]
		public void PathForId()
		{
			Assert.AreEqual("categories/1336.xml", Category.PathForId(1336));
		}
	}
}
